<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <title>Document</title>
  <style>
    html,
    body {
      height: 100%;
      margin: 0;
    }

    .father{
      position:relative;
      width: 100%;
      height: 100%;
      border: 1px solid #f00;
    }
    .child{
      position: absolute;
      width: 100px;
      height: 100px;
      background-color: #f00;
      top: 50%;
      left: 50%;
      margin-top: -50px;
      margin-left: -50px;
    }
  </style>
</head>

<body>
  <div class="father">
    <div class="child">123</div>
  </div>
</body>
<script src="./index.js"></script>

</html>